import {BasePage, BasePageData} from "../common/core/BasePage";
import {page, pageFunc} from "../common/PageBuilder";
import {UserPage} from "../common/partPages/UserPage";
import {pageMgr} from "../../modules/coreModule/managers/PageManager";
import {LevelChoicePage} from "../levelChoice/LevelChoicePage";
import {StudyPage} from "../study/StudyPage";
import {alertMgr} from "../../modules/coreModule/managers/AlertManager";
import {RoleType} from "../../modules/userModule/data/Role";

class Data extends BasePageData {
}

@page("exam", "考核中心")
export class ExamPage extends BasePage<Data> {

	/**
	 * 部分页
	 */
	public userPage: UserPage = new UserPage();

	// region 页面跳转

	/**
	 * 跳转至等级选择页面
	 */
	@pageFunc
	public async toLevelChoice() {
		if (!this.userPage.userInfo)
			await alertMgr().showAlert("尚未登录！");
		if (this.userPage.userInfo.certification?.role.type == RoleType.Instructor)
			await pageMgr().push(LevelChoicePage);
		else
			await alertMgr().showAlert("只有教官才需要进行考核！");
	}

	/**
	 * 跳转至内容学习页面
	 */
	@pageFunc
	public toStudy() {
		pageMgr().push(StudyPage).then();
	}

	// endregion
}
